import 'package:flutter_carplay/models/base_tab_bar_template.dart';
import 'package:flutter_carplay/models/grid/grid_button.dart';
import 'package:uuid/uuid.dart';

/// A template object that displays and manages a grid of items.
class CPGridTemplate extends BaseTabBarTemplate {
  /// The array of grid buttons as [CPGridButton] displayed on the template.
  final List<CPGridButton> buttons;

  /// Creates [CPGridTemplate] in order to display a grid of items as buttons.
  /// When creating the grid template, provide an array of [CPGridButton] objects.
  /// Each button must contain a title that is shown in the grid template's navigation bar.
  CPGridTemplate({
    title,
    systemIcon,
    showsTabBadge,
    dispose,
    selectThis,
    required this.buttons,
  }) : super(
            title: title,
            systemIcon: systemIcon,
            showsTabBadge: showsTabBadge,
            dispose: dispose,
            selectThis: selectThis);

  Map<String, dynamic> toJson() => {
        "_elementId": uniqueId,
        "title": title,
        "showsTabBadge": showsTabBadge,
        "systemIcon": systemIcon,
        "buttons": buttons.map((e) => e.toJson()).toList(),
        "templateType": templateType,
      };
}
